function refresh(){
	//刷新后导航栏显示，搜索框影藏
	if($("#segmentedControl").css("display") == 'none'){
		if($("#search").val()==""){
			$(".searchDiv").hide();
			$("#segmentedControl").show();
		}
	}
	listPatrol("mypatrol");
	listPatrol("iscomplete");
	listPatrol("nocomplete");
	listPatrol("notcomp");
}

$(function(){
	listPatrol("mypatrol");
	listPatrol("iscomplete");
	listPatrol("nocomplete");
	listPatrol("notcomp");
});
var dataHand = new AjaxHandler();
var psid = param.psid;

var search = null;
function listPatrol(id){
	$.proAjax({
		url: "/mobile/patrol",
		data: { psid: psid, result:$("#"+id+" #result").text(),search:search},
		success: function (data) {
			dataHand.arrayAddToHtml(id,data,"splitline",function(elm,datas){
				elm.find("a").off("click");
					if(datas.tourstate==1){
						elm.find("#tourstate").addClass("bg-green");
						elm.find("#tourstate").text("正常");
						elm.find("#reset_1").text("设定未完成");
						elm.find("#reset_2").text("设定异常");
						elm.find("#reset_1").attr("data-value","0");
						elm.find("#reset_2").attr("data-value","2");
					}else if(datas.tourstate==2){
						elm.find("#tourstate").addClass("bg-tint");
						elm.find("#tourstate").text("有异常");
						elm.find("#reset_1").text("设定正常");
						elm.find("#reset_2").text("设定未完成");
						elm.find("#reset_1").attr("data-value","1");
						elm.find("#reset_2").attr("data-value","0");
					}else {
						elm.find("#tourstate").addClass("bg-ee");
						elm.find("#tourstate").text("未完成");
						elm.find("#reset_1").text("设定正常");
						elm.find("#reset_2").text("设定异常");
						elm.find("#reset_1").attr("data-value","1");
						elm.find("#reset_2").attr("data-value","2");
					}
				(function(m,d){
					m.parent().parent().off("tap")
					m.find(".mui-slider-handle").on("click",function(e){
						e.preventDefault();
						e.stopPropagation();
						router.href("patrolRegister.html",{id:d});
					})
				}(elm,datas.id))
				
			});
			$(".mui-slider-right,.mui-disabled").find("a").off("click");
			$(".mui-slider-right,.mui-disabled").find("a").on("click",function(e){
				e.preventDefault();
				e.stopPropagation();
				var result = $(this).attr("data-value");
				var id = $(this).parent().prev().text();
				var divs = $(this).closest("li").attr("data-list")
				var btnArray = ['取消', '确定'];
				if($(this).text()=="删除"){
					mui.confirm('删除后无法恢复，确认删除？', '提示', btnArray, function(e) {
						if (e.index == 1) {
							
							$.proAjax({
								url: "/mobile/updatepatrol",
								data: { id:id, result:result},
								success: function (data) {
									listPatrol("mypatrol");
									listPatrol(divs);
								}
								});
						} 
					})
				}else{
					$.proAjax({
						url: "/mobile/updatepatrol",
						data: { id:id, result:result},
						success: function (data) {
							listPatrol("mypatrol");
							listPatrol("iscomplete");
							listPatrol("nocomplete");
							listPatrol("notcomp");
						}
						});
				}
				
				
			});
		}
	});
}
/*mui.plusReady(function(){
	listPatrol("mypatrol");
	listPatrol("iscomplete");
	listPatrol("nocomplete");
	listPatrol("notcomp");
});*/


